package com.ztgf.commodity.api.cms;

import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.commodity.models.bo.AttributesQueryBO;
import com.ztgf.commodity.models.dto.CommodityFilterAttributesDTO;
import com.ztgf.commodity.models.service.ICommodityFilterAttributesService;
import com.ztgf.commodity.models.vo.CommodityFilterAttributesNewVO;
import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
 * @author: chenyu.wang
 * @date: 2020-09-04
 * @description:
 */
@RestController
@RequestMapping("/cms/commodityFilterAttributes")
@Api(value = "CommodityFilterAttributesController", tags = "筛选属性管理接口")
public class CommodityFilterAttributesController {

    @DubboReference
    private ICommodityFilterAttributesService commodityFilterAttributesService;

    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "后台管理系统筛选属性列表", notes = "后台管理系统筛选属性列表")
    public Result queryPageList(AttributesQueryBO bo) {
        Page<CommodityFilterAttributesNewVO> page = commodityFilterAttributesService.newQueryPageList(bo);
        return new Result<>(page);
    }

    @PostMapping(value = "/getById")
    @ApiOperation(value = "根据id获取筛选属性", notes = "根据id获取筛选属性")
    public Result getById(Long id) {
        if (null == id) {
            return new Result<>(CodeEnum.FAIL_100002);
        } else {
            CommodityFilterAttributesNewVO dto = commodityFilterAttributesService.queryById(id);
            return new Result<>(dto);
        }
    }

    @PostMapping(value = "/add")
    @ApiOperation(value = "添加筛选属性", notes = "添加筛选属性")
    public Result add(String object) {
        if (StringUtils.isNotBlank(object)) {
            Result<List<String>> result = commodityFilterAttributesService.add(object);
            return new Result<>(result);
        } else {
            return new Result<>(CodeEnum.FAIL_100002);
        }
    }

    @PostMapping(value = "/updateById")
    @ApiOperation(value = "修改筛选属性", notes = "修改筛选属性")
    public Result updateById(String object) {
        if (StringUtils.isNotBlank(object)) {
            Result<List<String>> result = commodityFilterAttributesService.updateById(object);
            return new Result<>(result);
        } else {
            return new Result<>(CodeEnum.FAIL_100002);
        }
    }

    @PostMapping(value = "/queryList")
    @ApiOperation(value = "后台管理系统筛选属性列表,用于类目新增、修改", notes = "后台管理系统筛选属性列表,用于类目新增、修改")
    public Result queryList() {
        List<CommodityFilterAttributesDTO> list = commodityFilterAttributesService.queryList();
        return new Result<>(list);
    }

}
